<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
//calendar中完成了這些操作，在這裡可以不實現
//檢查是否存在相同的event 
include_once "common.php";
class event
{
    function event()
    {
        global $baseinfo_c;
         $baseinfo_c =new baseinfo_common();
    }
    function existEvent($subject,$etid,$vid,$st,$et,$isallday,$eid="")
    {
        //如果$isallday那麼僅取日期，如果不是則要包含日期，時間
        //$eid=""代表新增，否則代碼修改，修改時不包含本身的存在處理
        $sql="SELECT count(1) as existNum FROM event
                WHERE `subject`='".$subject."' AND etid='".$etid."' AND vid='".$vid."' AND  (event.delete_flag=0 OR event.delete_flag IS NULL) ";
        if($isallday==1)            
        {
	     $sql=$sql."AND CAST(event.start_time AS DATE)='".$st."' AND 
		CAST(event.end_time AS DATE) ='".$et."' ";
        }
        else
        {
             $sql=$sql."AND event.start_time='".$st."' AND 
		event.end_time ='".$et."' ";
        }
        if($eid!="")
        {
            $sql=$sql." AND eid!=".$eid;
        }
        global $baseinfo_c;
        $handle= $baseinfo_c->execSql($sql);
        if($handle)
        {
            $row = mysql_fetch_object($handle);
            $existkey=$row->existNum;
            if(intval($existkey)>=1)
            {
                return true;//存在
            }
            else
            {
                return false;//不存在 
            }
        }
        else
        {
            return "Sql error";
        }
    }
}
?>
